<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: wsh
 * @Date: 2024-03-25 10:15:02
 * @LastEditors: uphldjx 1373577124@qq.com
 * @LastEditTime: 2024-06-19 15:25:37
-->
<!-- 项目管理(菜单仅开放各区民政) -->
<template>
	<BaseContainer>
		<aplid-base-crud ref="crud" class="w-100" v-bind="{ ...baseConfig, ...$attrs }" :operateFormate="operateFormate">
			<template v-slot:entrustingPartyDialog="{ row, show }">
				<entrustingParty @rechange="handleOperate" @refresh="handleRefresh" :nowRowData="row"> </entrustingParty>
			</template>
			<template v-slot:undertakingUnitDialog="{ row, show }">
				<undertakingUnit @rechange="handleOperate" @refresh="handleRefresh" :nowRowData="row"> </undertakingUnit>
			</template>
			<template #organizationName="{ row }">
				<el-button type="primary" size="small" @click="applyReason(row, 'organizationName')">查看</el-button>
			</template>
			<template #sampleTime="{ row }">
				<el-button type="primary" size="small" @click="applyReason(row, 'sampleTime')">查看</el-button>
			</template>
			<template v-slot:RuleSetDialog="{ row,show }">
        <govProjectRule  :project="row" v-if="show && row.belongProject !='elderlyMeal'"></govProjectRule>
        <MealProjectRule :project="row" v-if="show && row.belongProject =='elderlyMeal'"></MealProjectRule>
			</template>
		</aplid-base-crud>
		<el-dialog v-model="visible" :title="title" width="60%">
			<bulletHole :dataArray="dataArray" :title="title"></bulletHole>
		</el-dialog>
	</BaseContainer>
</template>

<script setup lang="ts">
import { baseConfig } from './config'
import entrustingParty from './entrustingParty/index.vue'
import undertakingUnit from './undertakingUnit/index.vue'
import govProjectRule from '@/views/homeCare/govProjectRule/index.vue'
import MealProjectRule from '@/views/homeCare/elderlyMeal/ProjectRule/index.vue'
// import DetailPage from '@/views/aplid/DetailPage/index.vue'
import bulletHole from './bulletHole.vue'
import { setStore, getStore } from '@/utils/store'

const belongProject = getStore('belongProject')

const handleRefresh = () => {
	nextTick(() => {
		crud.value.refreshChange()
	})
}

const operateFormate = (row, type) => {
	return new Promise((resolve, reject) => {
		if (type == 'delete' || type == 'edit') {
			if (belongProject) {
				const projectKey = `${belongProject}-project-info`
				const projectInfo = getStore(projectKey) || {}
				if (row.id == projectInfo.subprojectId) {
					const obj = {
						subprojectId: row.id,
						projectStatus: row.projectStatus,
						subprojectName: row.projectName,
						belongProject,
					}
					setStore(projectKey, type == 'edit' ? obj : '')
				}
			}
		}
		resolve(row)
	})
}

const handleOperate = (type, row, title) => {
	nextTick(() => {
		crud.value.handleOperate(type, row, title)
	})
}

const crud = ref(null)
const visible = ref(false)
const title = ref()
const dataArray = ref([])
const applyReason = (row, type) => {
	if (type == 'organizationName') {
		title.value = '服务承接单位'
		dataArray.value = row.omProjectCooperatePOList?.filter((obj) => obj.bindType == 1)
	} else if (type == 'sampleTime') {
		title.value = '委托单位'
		dataArray.value = row.omProjectCooperatePOList?.filter((obj) => obj.bindType == 2)
	}
	visible.value = true
}
</script>

<style lang="scss" scoped></style>
